﻿using HelperTool_WHW;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MainFrame
{
   public class MesTCP
    {
        int Conut = 0;
        public MesTCP(SocketHelper socket)
        {
            m_socket = socket;
            m_socket.clientReceivedProc += messageReceived;
            Conut++;
         }
        public SocketHelper m_socket;
        public List<string> msgList=new List<string>();
        public object lockMsg = new object();
        private void messageReceived(string msg)
        {
            displalyInfo.displayInfoMain("客户端接收到消息" + msg);
            lock (lockMsg)
            {
                if (!string.IsNullOrEmpty(msg) && msg.IndexOf("@") == 0 && msg.Count(a => a == '@') == 1 && (msg.Contains("\r") || msg.Contains("\n")))
                    msgList.Add(msg.Replace("\r", "").Replace("\n", ""));
                else
                {
                    displalyInfo.displayInfoMain("客户端接收到消息" + msg + "不在列表里");
                }
            }
        }
        public int sendMsg(string msg)
        {
            msg += Environment.NewLine;
            displalyInfo.displayInfoMain("客户端发送消息内容" + msg);
            
            return m_socket.Tcp_client.Send(Encoding.UTF8.GetBytes(msg)) ? 1 : -1;
        }

    }
   
    public enum e_TCPStatus
    {
        未知,
        Fail,
        OK,
    }
    public class Cmd
    {
        public string action { get; set; }
        public string cmd { get; set; }
      
    }
}
